<template>
    <el-form class="login" ref="form" :model="form" label-width="80px">
        <el-form-item label="账号">
            <el-input v-model="form.username"></el-input>
        </el-form-item>
        <el-form-item label="密码">
            <el-input v-model="form.password"></el-input>
        </el-form-item>
        <el-form-item label="身份">
            <el-radio-group v-model="form.type">
                <el-radio label="学生"></el-radio>
                <el-radio label="管理员"></el-radio>
            </el-radio-group>
        </el-form-item>
        <el-form-item class="login-btn">
            <el-button type="primary" @click="onSubmit">登录</el-button>
        </el-form-item>
    </el-form>
</template>
<script>

import{loginApi} from '../api/loginApi'


export default {
    data() {
        return {
            form: {
                username: '',
                password: '',
                type: '学生'
            }
        }
    },
    methods: {
       async onSubmit() {
        let {data}=await loginApi(this.form)   
        if (data.code == 200) {
           
            sessionStorage.setItem('user',JSON.stringify(data.data));
            sessionStorage.setItem('token', data.token);

            alert('登录成功')
               
            }
    
           

           
           
           
         /*    alert('登录成功')
            this.$router.push({name:'noticehome',params:{id:1,name:this.form.username,password:this.form.password}}) */
            
           
        }
    }
}
</script>
<style scoped lang="less">
.login {
    width: 400px;
    height: 300px;
    position: absolute;
    left: 50%;
    top: 50%;
    margin-left: -200px;
    margin-top: -200px;
    border: 1px solid #eee;
    box-sizing: border-box;
    padding: 30px 30px 0 0;
}
</style>
<style lang="less">
.login-btn {
    .el-form-item__content {
        margin-left: 30px !important;
        text-align: center;
    }
}
</style>